package com.scau402.system.controller;

import com.scau402.common.annotation.Log;
import com.scau402.common.core.controller.BaseController;
import com.scau402.common.core.domain.AjaxResult;
import com.scau402.common.enums.BusinessType;
import com.scau402.system.domain.SysCiphertext;
import com.scau402.system.service.ISysCiphertextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 暗码Controller
 *
 * @author ruoyi
 * @date 2023-09-27
 */
@RestController
@RequestMapping("/system/ciphertext")
public class SysCiphertextController extends BaseController {
    @Autowired
    private ISysCiphertextService sysCiphertextService;

    /**
     * 获取暗码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ciphertext:query')")
    @GetMapping("/getCiphertext")
    public AjaxResult getInfo(Long typeId) {
        return success(sysCiphertextService.selectSysCiphertextByTenantId(typeId));
    }

    /**
     * 新增暗码
     */
    @PreAuthorize("@ss.hasPermi('system:ciphertext:add')")
    @Log(title = "暗码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysCiphertext sysCiphertext) {
        return toAjax(sysCiphertextService.insertSysCiphertext(sysCiphertext));
    }

    /**
     * 修改暗码
     */
    @PreAuthorize("@ss.hasPermi('system:ciphertext:edit')")
    @Log(title = "暗码", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysCiphertext sysCiphertext) {
        return toAjax(sysCiphertextService.updateSysCiphertext(sysCiphertext));
    }

    /**
     * 明码转换暗码
     */
    @PreAuthorize("@ss.hasPermi('system:ciphertext:change')")
    @PostMapping("/change")
    public AjaxResult change(@RequestBody Map<String, String> params) {
        String price = params.get("price");
        return success(sysCiphertextService.changePlaintextToCiphertext(price));
    }
}
